//
//  TZFriendVc.m
//  BSBDJ
//
//  Created by user on 16/5/23.
//  Copyright © 2016年 Burning. All rights reserved.
//

#import "TZFriendVc.h"
#import "TZLoadAndRegistVc.h"
#import "TZCoverView.h"
#import "VersionTool.h"
#import "QRCodeTool.h"
#import "TZQRCodeController.h"
#import "FYLoginTranslation.h"
#import "TZMyInfoVc.h"

@interface TZFriendVc ()<UIScrollViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIViewControllerTransitioningDelegate>

@property (strong, nonatomic) FYLoginTranslation* login;
@property (weak, nonatomic) IBOutlet UIButton *loadBtn;

@end

@implementation TZFriendVc

- (FYLoginTranslation *)login
{
    if (!_login) {
        _login = [[FYLoginTranslation alloc] initWithView:self.loadBtn];
    }
    return _login;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self setupNavigationbarbuttonItem];

}
- (IBAction)loadAndRegist:(id)sender {
    
   
    TZLoadAndRegistVc *infoVc = [TZLoadAndRegistVc new];
    infoVc.transitioningDelegate = self;
    [self presentViewController:infoVc animated:YES completion:nil];
    //
        [self performSelector:@selector(finishTransition) withObject:nil afterDelay:2];
}


- (void)setupUI{
    self.view.backgroundColor = XMGColor(244, 244, 244);
}

// 设置navigationbarbuttonitem
- (void)setupNavigationbarbuttonItem{
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"btn_date_plus"] highImage:nil target:self action:@selector(clickMoreBtn)];
}
// navigationbarbuttonitem点击事件
- (void)clickMoreBtn{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择打开方式" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    ///扫一扫
    UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"扫一扫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        TZQRCodeController *qrcodeVc = [TZQRCodeController new];
        [self.navigationController pushViewController:qrcodeVc animated:YES];
    }];
    ///识别相册二维码
    UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"打开相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:nil];
    }];
    /// 取消
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];
    
    [alert addAction:photoAction];
    [alert addAction:albumAction];
    [alert addAction:cancleAction];
    [self presentViewController:alert animated:YES completion:nil];
    
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    
    // 点击照片
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    
    QRCodeTool *codeTool = [QRCodeTool shareInstance];
    [codeTool detectorQRCode:image];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    // .....
    
    // 关闭选择图片界面
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark --------------
#pragma mark 代理方法
- (void)finishTransition
{
    [self.login stopAnimation];
}

#pragma mark UIViewControllerTransitioningDelegate
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    self.login.reverse = YES;
    return self.login;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
    self.login.reverse = NO;
    return self.login;
}

- (void)dealloc{
    NSLog(@"delloc----firend");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
